package com.hc.server.conn.mall;

import org.json.JSONException;
import org.json.JSONObject;

public class MallResponse {

	private static final String CODE = "code";
	private static final String RESULT = "result";
	private int respCode = 0;
	private JSONObject result;

	public static MallResponse paser(String respMsg) throws JSONException {
		JSONObject tmpObj = new JSONObject(respMsg);
		MallResponse resp = new MallResponse();
		resp.respCode = tmpObj.getInt(CODE);
		resp.result = tmpObj.getJSONObject(RESULT);
		return resp;
	}

	private MallResponse() {

	}

	public int getRetCode() {
		return this.respCode;
	}

	public JSONObject getResult() {
		return this.result;
	}

	public String getErrorMsg() {
		String errMsg = "";
		switch (respCode) {
		case 101:
			errMsg = "查询产品参数缺失";
			break;
		case 102:
			errMsg = "产品不存在";
			break;
		case 103:
			errMsg = "查询产品参数错误(类型，格式)";
			break;
		case 1001:
			errMsg = "订单参数错误";
			break;
		case 1002:
			errMsg = "产品不存在";
			break;
		case 1003:
			errMsg = "产品库存不足";
			break;
		case 1004:
			errMsg = "订单生成失败";
			break;
		case 1005:
			errMsg = "订单不存在";
			break;
		default:
			errMsg = "商城未知错误";
			break;
		}
		return errMsg;
	}

}
